package org.sakai.controller;


import org.sakai.mapper.MedicinesOrderMapper;
import org.sakai.service.ConsultService;
import org.sakai.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/pay")
@Controller
public class PayController {
    @Autowired
    private PayService payService;
    @Autowired
    private ConsultService consultService;
    @Autowired
    private MedicinesOrderMapper medicinesOrderMapper;
    //必须加ResponseBody注解，否则spring会寻找thymeleaf页面
    @PostMapping("/consult/payFinished/{orderId}")
    public ResponseEntity<String> payFinished(@PathVariable String orderId){
        consultService.updateConsultStatus(orderId, "待接诊");
        System.out.println("支付成功");
        return new ResponseEntity<>(HttpStatus.OK);
    }
    @ResponseBody
    @RequestMapping("/consult/{orderId}")
    public String payForConsult(@PathVariable String orderId) {
        Double payment = consultService.getPriceByOrderId(orderId).doubleValue();
        return payService.sendRequestToAlipay(orderId, payment);
    }
}
